<%--
  Created by IntelliJ IDEA.
  User: 71027
  Date: 2019/4/30
  Time: 18:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册你的商店</title>
    <%@include file="common/common.jsp"%>
</head>
<body>
<h1>注册商店</h1>
<h1 align="center">欢迎你，${userid}</h1>
<form>
    <div class="form-group">
        商店ID：<input type="text" name="storeid" placeholder="输入商店ID"/>
        <span id="storeidspan"></span>
    </div>
    <div class="form-group">
        商店描述：<input id="description" type="text" name="description" placeholder="输入商店的描述"/>
    </div>

</form>
<button id="submit" onclick="storeregister()">提交</button>
<a href="javascript:history.go(-1)">返回</a>
<%--别的？--%>
<div id="prompt"></div>

<%--下面是js代码上面是有问题吗？--%>
<script type="text/javascript">
    function storeregister() {
        /*这个可以作为默认模板，因为经常可以用，注册页面。*/

        var res=false;

        var storeid=$("input[name='storeid']");
        var description=$("input[name='description']");
        if (storeid.val() === "" || description.val() === "") {
            var storeidspan=document.getElementById("storeidspan");
            storeidspan.innerHTML="不能为空";
            storeidspan.style.color="red";
            return false;
        }

        var data={};
        data["userid"]='${userid}';/*写在这就好了？？？？*/

        var arr=$('form').serializeArray();
        $.each(arr,function () {
            data[this.name]=this.value;
        });
        alert(JSON.stringify(data));


        $.ajax({
            url:"http://localhost:8080/Github_war_exploded/store/storeregisteraction",
            type:"GET",
            data:data,


            success:function (data) {
                var prompt=document.getElementById("prompt");
                prompt.innerHTML=data;
                prompt.style.color="red";
                window.location.href="http://localhost:8080/Github_war_exploded/user/personal?userid=${userid}";
            },error:function (msg) {
                alert('ajax error');
                console.log(msg);
            }
        });
    }
</script>
</body>
</html>
